% Auxiliary Function: get_default_field
%   Description:
%       Function to retrieves the value from a structure, with a default value if the field is
%       missing or the structure is empty
%   Inputs:
%       s: Input structure (can also be empty)
%       field_name: A string or character array representing the name of the field to access
%       default_value: The value to return if the field doesn't exist or the structure is empty
%   Outputs:
%       v: The value of s.(field_name) if it exists, otherwise return default_value
%   Example:
%       input_struct.color = 'red';
%       out1 = get_default_field(settings, 'color', 'blue'); % returns 'blue'
%       out2 = get_default_field(settings, 'size', 'small'); % returns 'small' (default)

function v = get_default_field(s, field_name, default_value)
    % If structure 's' has field named 'field_name', then the field is returned
    if ~isempty(s) && isfield(s, field_name)
        v = s.(field_name);
    % If the field named 'field_name' is missing, the 'default_value' is returned
    else
        v = default_value;
    end
end